fix(ai): derive safe model output token limits - #1632
Merged
Conversation
Hide output-token configuration from the model form while preserving existing explicit overrides. Derive a shared output limit for model requests and context compression when the value is absent or invalid. Reject context windows below 32K and fall back with a warning when an explicit output limit exceeds 40% of the context window. Refs GCWing#1558
wsp1911
marked this pull request as ready for review
July 19, 2026 10:44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
max_tokensoverrides.Fixes #1558
Type and Areas
Type:
Bug fix, UI/UX
Areas:
Rust core, web UI, AI model configuration
Motivation / Impact
Users could set maximum output Tokens equal to the context window without understanding that BitFun reserves output capacity before triggering context compression. This left almost no input budget and caused repeated compaction.
The form now only asks for the context window. Existing manual
max_tokensvalues remain supported when within 40% of the configured context window; invalid values safely fall back at runtime without rewriting user configuration.Verification
pnpm run type-check:webpnpm run i18n:auditpnpm run fmt:rscargo test -p bitfun-core --lib derives_the_largest_output_tier_within_one_quarter_of_context -- --nocapturecargo test -p bitfun-core --lib falls_back_to_the_automatic_output_limit_when_configured_limit_is_too_large -- --nocapturecargo test -p bitfun-core --lib preserves_a_configured_output_limit_within_forty_percent_of_context -- --nocapturecargo test -p bitfun-core --lib rejects_a_context_window_smaller_than_the_supported_minimum -- --nocapturecargo test -p bitfun-core --lib rejects_a_model_context_window_smaller_than_32k -- --nocapturecargo test -p bitfun-core --lib compression_trigger_budget_uses_the_automatic_output_tier_when_max_tokens_is_unset -- --nocapturegit diff --cached --checkThe focused tests were run before the final data-only addition of the 24K automatic tier; no dedicated test was added for that tier by design.
Reviewer Notes
Checklist